package com.ruoyi.web.controller.consume;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consume.domain.CartonApplyCon;
import com.ruoyi.consume.service.ICartonApplyConService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 纸箱领用Controller
 *
 * @author ruoyi
 * @date 2021-07-23
 */
@Api("纸箱领用")
@RestController
@RequestMapping("/consume/cartonap")
public class CartonApplyConController extends BaseController
{
    @Autowired
    private ICartonApplyConService cartonApplyService;

    /**
     * 查询纸箱领用列表
     */
    @ApiOperation("查询纸箱领用列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:cartonap:list')")
    @GetMapping("/list")
    public TableDataInfo list(CartonApplyCon cartonApplyCon)
    {
        startPage();
        List<CartonApplyCon> list = cartonApplyService.selectCartonApplyList(cartonApplyCon);
        return getDataTable(list);
    }

    /**
     * 导出纸箱领用列表
     */
    @PreAuthorize("@ss.hasPermi('consume:cartonap:export')")
    @Log(title = "纸箱领用", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CartonApplyCon cartonApplyCon)
    {
        List<CartonApplyCon> list = cartonApplyService.selectCartonApplyList(cartonApplyCon);
        ExcelUtil<CartonApplyCon> util = new ExcelUtil<CartonApplyCon>(CartonApplyCon.class);
        return util.exportExcel(list, "纸箱领用数据");
    }

    /**
     * 获取纸箱领用详细信息
     */
    @PreAuthorize("@ss.hasPermi('consume:cartonap:query')")
    @GetMapping(value = "/{cartonApplyId}")
    public AjaxResult getInfo(@PathVariable("cartonApplyId") Long cartonApplyId)
    {
        return AjaxResult.success(cartonApplyService.selectCartonApplyById(cartonApplyId));
    }

    /**
     * 新增纸箱领用
     */
    @PreAuthorize("@ss.hasPermi('consume:cartonap:add')")
    @Log(title = "纸箱领用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CartonApplyCon cartonApplyCon)
    {
        return toAjax(cartonApplyService.insertCartonApply(cartonApplyCon));
    }

    /**
     * 修改纸箱领用
     */
    @PreAuthorize("@ss.hasPermi('consume:cartonap:edit')")
    @Log(title = "纸箱领用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CartonApplyCon cartonApplyCon)
    {
        return toAjax(cartonApplyService.updateCartonApply(cartonApplyCon));
    }

    /**
     * 删除纸箱领用
     */
    @PreAuthorize("@ss.hasPermi('consume:cartonap:remove')")
    @Log(title = "纸箱领用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cartonApplyIds}")
    public AjaxResult remove(@PathVariable Long[] cartonApplyIds)
    {
        return toAjax(cartonApplyService.deleteCartonApplyByIds(cartonApplyIds));
    }

    /**
     * 更新库存量表
     */
    @ApiOperation("更新库存量表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:cartonap:amount')")
    @Log(title = "纸箱领用", businessType = BusinessType.UPDATE)
    @PutMapping("/amount")
    public AjaxResult amount(@RequestBody CartonApplyCon cartonApplyCon)
    {
        return toAjax(cartonApplyService.updateCartonAmount(cartonApplyCon));
    }

    /**
     * 更新领用状态
     */
    @ApiOperation("更新领用状态")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:cartonap:consu')")
    @Log(title = "纸箱领用", businessType = BusinessType.UPDATE)
    @PutMapping("/consu/{cartonApplyId}")
    public AjaxResult consume(@PathVariable("cartonApplyId") Long cartonApplyId)
    {
        return toAjax(cartonApplyService.updateConsumeStatus(cartonApplyId));
    }

    /**
     * 退回操作
     */
    @ApiOperation("退回操作")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:cartonap:back')")
    @Log(title = "纸箱领用", businessType = BusinessType.UPDATE)
    @PutMapping("/back/{cartonApplyId}")
    public AjaxResult back(@PathVariable("cartonApplyId") Long cartonApplyId)
    {
        return toAjax(cartonApplyService.updateApprovalStatus(cartonApplyId));
    }
}
